package com.wy.powerbuilder.controller.hxl;

import com.github.pagehelper.PageInfo;
import com.wy.powerbuilder.entity.hxl.PageEntity;
import com.wy.powerbuilder.entity.hxl.carcontract;
import com.wy.powerbuilder.entity.hxl.carseat;
import com.wy.powerbuilder.mapper.hxl.carseatMapper;
import com.wy.powerbuilder.service.hxl.carseatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Set;

@Controller
public class carseatController {
    @Autowired
    private carseatMapper carseatmapper;
    @Autowired
    private carseatService car;

    //查询车位
    @RequestMapping(value = {"/carseatController"})
    public String selByPage(Integer pageNum, Model model,String cS_number){

        //实现我们的分页  每页显示两条   pageInfo应该放在那里 model modelAndView map
        PageInfo<carseat> pageInfo = car.selByPagecar(pageNum, 10,cS_number);
        model.addAttribute("pageInfo",pageInfo);
        if(cS_number==null){
            cS_number="";
        }
        model.addAttribute("cS_number",cS_number);

        return "management";
    }

//连表查询合同表和车位表
    @RequestMapping(value = {"/managementselect"})
    public String managementselect(String cS_number, Model model) {
        carseat smbid = car.managementselect(cS_number);
        model.addAttribute("smbid",smbid);
        return "managementselect";
    }

    //车位管理删除
    @RequestMapping(value = {"/cwdelete"})
    public String delete(Integer cs_id) {
        int result = car.delete(cs_id);
        if (result>0){
            return "redirect:/selePageInfo";
        }
        return "error";
    }
    //车位管理批量删除
    @ResponseBody
    @RequestMapping("/deletes")
    public String deleteall(String cs_id) {

/*
       for (int i=0;i<cs_id.length();i++){
        String subStr = cs_id.substring(i,cs_id.indexOf(","));
        String str2= cs_id.substring(subStr.length()+1,cs_id.length());

              System.out.println(str2 +"hh");
              abc = car.deleteall(str2);

     }*/
        int i=0;
        int len=3;
        for (;i+len<=cs_id.length();i+=len){
            System.out.println(cs_id.substring(i,i+len)+"333");
            System.out.println(i+"111");
            System.out.println(len+"222");
            int abc = car.deleteall(cs_id.substring(i,i+len));
        }
        return "success";

    }

}
